
* Non-parametric Analysis

use book-basedata-replication, clear
	
*generate ordinal indicator of mediation type
gen med_types=nomanip2
replace med_types=2 if manip2==1
tab med_types nomanip2, miss
tab med_types manip2, miss
label define med_types 0 "No mediation" 1 "Other mediation" 2 "Manipulation"
label values med_types med_types


*calculate Kaplan-Meier survival function
sts graph if _t<3650, by(med_types)  title("") ///
		xtitle("Time since last crisis in days") ///
		ytitle(Proportion of dyads still at peace) legend(label(1 "No mediation") ///
		label(2 "Other mediation") label(3 "Manipulation") ///
		region(lwidth(none)) row(1)) ///
		plot1opts(lp(solid) lc(gs10))  ///
		plot2opts(lp(dash_dot) lc(gs5)) ///
		plot3opts(lp(dash) lc(black)) 
graph export kmplot.pdf, replace
graph export kmplot.png, replace


sts list, by(med_types) at(1095 1825 2555 3650)

*calculate Kaplan-Meier survival function for non-manipulated vs. manipulated 
sts graph if _t<3650 & med_types>0, by(med_types)  title("") ///
		xtitle("Time since last crisis in days") ci ///
		ytitle(Proportion of dyads still at peace) ///
		plot1opts(lp(solid) lc(black)) ci1opts(lcol(gs10%30)  fcol(gs10%30)) ///
		plot2opts(lp(shortdash) lc(black))  ci2opts(lcol(gs10%30)  fcol(gs10%30))
